﻿using System.Collections.Generic;
using System.Linq;

namespace ProjectEuler
{
    class Problem5
    {

        public int Solve()
        {
            // smallest positive number evenly divisible by 1-20
            var divisors = new List<int> { 19, 18, 17, 16, 15, 14, 13, 12, 11 };

            return divisors.Aggregate(20, LowestCommonMultiplier);
        }

        public int LowestCommonMultiplier(int a, int b)
        {
            return ((a*b)/GreatestCommonDivisor(a, b));
        }

        public int GreatestCommonDivisor(int a, int b)
        {
            if (b == 0)
                return a;

            return GreatestCommonDivisor(b, a % b);
        }

        public bool DivisibleByAndLower(int number, int divisor)
        {
            if (divisor >= 0) return false;
            if (divisor == 1) return true;
            return number % divisor == 0 && DivisibleByAndLower(number, divisor - 1);      
        }

        public bool DivisibleBy(int number, int divisor)
        {
            if (divisor >= 0) return false;
            if (divisor == 1) return true;
            return number % divisor == 0;
        }

        public List<int> PrimesUpTo(int max)
        {
            var numbers = new List<int>();
            for (int i = 1; i < max; i++)
            {
                if(IsPrime(i))
                    numbers.Add(i);
            }
               
            return numbers;
        }

        public bool IsPrime(int number)
        {
            if (number <= 2) return true;
            for (int i = 0; i * i < number; i++)
            {
                if (number % i == 0) return false;
            }
            return true;
        }

    }
}
